
var app = getApp();
var ApiUrl = app.globalData.ApiUrl;
var order_id="";
var key = wx.getStorageSync("key");
Page({

  /**
   * 页面的初始数据
   */
  data: {
  
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    var that = this;
    order_id = options.order_id;
    key = wx.getStorageSync("key");
    var starClass = new Array();
    var desccreClass = new Array();
    var serviceClass = new Array();
    var deliveryClass = new Array();
    for(var i=0;i<5;i++){
      starClass[i] = 'star-level-solid';
      desccreClass[i] = 'star-level-solid';
      serviceClass[i] = 'star-level-solid';
      deliveryClass[i] = 'star-level-solid';
      
    }
    wx.request({
      url: ApiUrl + "/index.php?act=member_evaluate&op=index",
      data: {'key':key,'order_id':order_id},
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: "GET",
      success: function (res) {
        
        that.setData({
          order_goods:res.data.datas.order_goods,
          store_info: res.data.datas.store_info, 
          starClass: starClass,
          score: 5 ,
          desccreClass: desccreClass, 
          desccreditscore:5,
          serviceClass: serviceClass,
          servicescore:5,
          deliveryClass: deliveryClass,
          deliveryscore:5,
          order_id: order_id,
          key: key     
        }); 
      }
    })
  },
  starlevel:function( e ){
    var starindex = e.currentTarget.dataset.i;
    var starClass = new Array();
    var score = starindex+1;
    for (var a = 0; a < 5; a++) {
      if (a <= starindex) {
        starClass[a] = "star-level-solid";
        
      } else {
        starClass[a] = "star-level-hollow";
      }
    }

    var that = this;
    that.setData({
      starClass: starClass, 
      score: score     
    });
  },
  desccrelevel:function (e) {
    var starindex = e.currentTarget.dataset.i;
    var desccreClass = new Array();
    var desccreditscore = starindex + 1;
    for (var a = 0; a < 5; a++) {
      if (a <= starindex) {
        desccreClass[a] = "star-level-solid";  
      } else {
        desccreClass[a] = "star-level-hollow";
      }
    }
    var that = this;
    that.setData({
      desccreClass: desccreClass,
      desccreditscore: desccreditscore
    });
  },
  deliverylevel: function (e) {
     
    var starindex = e.currentTarget.dataset.i;
    var deliveryClass = new Array();
    var deliveryscore = starindex + 1;
    for (var a = 0; a < 5; a++) {
      if (a <= starindex) {
        deliveryClass[a] = "star-level-solid";
      } else {
        deliveryClass[a] = "star-level-hollow";
      }
    }
    var that = this;
    that.setData({
      deliveryClass: deliveryClass,
      deliveryscore: deliveryscore
    });
  },
  servicelevel: function (e) {
    var starindex = e.currentTarget.dataset.i;
    var serviceClass = new Array();
    var servicescore = starindex + 1;
    for (var a = 0; a < 5; a++) {
      if (a <= starindex) {
        serviceClass[a] = "star-level-solid";


      } else {
        serviceClass[a] = "star-level-hollow";
      }
    }
    var that = this;
    that.setData({
      serviceClass: serviceClass,
      servicescore: servicescore
    });
  },
  chooseImage: function (options) {
    var filekey = options.currentTarget.dataset.filekey;
    var that = this;
    wx.chooseImage({
      count: 3,
      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
      success: function (res) {
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
        var tempFilePaths = res.tempFilePaths;
        wx.uploadFile({
          url: "https://test.mvip100.com/mobile/index.php?act=sns_album&op=file_upload",
          filePath: tempFilePaths[0],
          name: 'file',
          formData: {
            'key': key,
          },
          success: function (result) {
            
            var datas = JSON.parse(result.data);
             
            var picname = new Array();
            var file_name = new Array();
            picname[filekey] = datas.datas.file_url;
            file_name[filekey] = datas.datas.file_name
            that.setData({
              pic: picname,
              file_name: file_name
            });
            
          }
        })
      }

    });
  },
  formSubmit: function (params) {
   
    var that = this;
    var paramArr = {};
    paramArr = params.detail.value;
 
    paramArr.key = that.data.key;
    paramArr.order_id = that.data.order_id;
    
      wx.request({
        url: ApiUrl + '/index.php?act=member_evaluate&op=save',
        data: paramArr,
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        method: 'post',
        success: function (result) {
         
          if (result.data.code == "200") {
            wx.reLaunch({
              url: '/pages/order/order',
            })
            
          }
        }
      })
    

  },
})